<?php
/**
 * 学校概况类
 * @author Administrator
 *
 */
class ArticleSchoolAction extends BaseAction {
	/**
	 * 领导机构列表
	 */
	public function article_school_list(){
		if($_GET['c_id']){
			$where = "ac_id = ".$_GET['c_id'];
		}else{
			$where = "ac_id=7";
		}
		$where .= $this->my_where();
		import('ORG.Util.Page');// 导入分页类
		$count = M('Article')->where($where)->count();//总条数
		$Page = new Page($count,10);//每页显示10条
		$show = $Page->show();
		$list = M('Article')->where($where)->order('sort')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign("list",$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
	}
	/*
	 * 添加领导机构人员
	 */
	public function article_school_leader_add(){
		if($_POST){
			$_POST['time'] = time();
			$_POST['ac_id'] = 7; //传入领导机构的分类ID
			$_POST['content'] = stripslashes($_POST['content']);
			$info = $this->upload();
			if ($info){
				$savepath = $info[0]["savepath"];
				$savepath = substr($savepath, 1,strlen($savepath) - 1);
				$_POST['pic_url'] = $savepath.$info[0]["savename"];//封面设置
			}
			 M('Article')->add($_POST);
			$this->success('添加成功',U('ArticleSchool/article_school_list',array('c_id'=>7)));
			exit;
		}
		$this->display();
	}
	/**
	 * 修改领导人员信息
	 */
	public function article_school_leader_update(){
		if ($_POST){
			$info = $this->upload_();
			if ($info){
				$savepath = $info[0]["savepath"];
				$savepath = substr($savepath, 1,strlen($savepath) - 1);//图片上传路径处理去掉.
				$_POST['pic_url'] = $savepath.$info[0]["savename"];//上传图片设置
			}
			$_POST['content'] = stripslashes($_POST['content']);
			M('Article')->save($_POST);
			$this->success('更新成功',U('ArticleSchool/article_school_list',array('p'=>$_POST['p'],'c_id'=>$_POST['c_id'],'search_word'=>$_POST['search_word'])));
			exit;
		}
		$search_word = $_GET['search_word'];
		$p = $_GET['p'];
		$c_id = $_GET['c_id'];
		$obj = M('Article')->where("id=".$_GET['id'])->find();
		$this->assign("obj",$obj);
		$this->assign('p',$p);
		$this->assign('c_id',$c_id);
		$this->assign('search_word',$search_word);
		$this->display();
	}
	/**
	 * 大美英才列表
	 */
	public function article_school_pic_list(){
		$where = '';
		if($_GET['c_id']){
			$where = "ac_id = ".$_GET['c_id'];
		}else{
			$where = "ac_id=8";
		}
		$where .= $this->my_where();
		import('ORG.Util.Page');// 导入分页类
		$count = M('Article')->where($where)->count();//总条数
		$Page = new Page($count,10);//每页显示10条
		$show = $Page->show();
		$list = M('Article')->where($where)->order('sort')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign("list",$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
	}
	/**
	 * 添加大美英才
	 */
	public function article_school_pic_add(){
		if($_POST){
			$_POST['time'] = time();
			$_POST['ac_id'] = 8;
			$info = $this->upload();
			if($info){
				$savepath = $info[0]["savepath"];
				$savepath = substr($savepath, 1,strlen($savepath) - 1);
				$_POST['pic_url'] = $savepath.$info[0]["savename"];//封面设置
			}
			M('Article')->add($_POST);
			$this->success('添加成功',U('ArticleSchool/article_school_pic_list',array('c_id'=>8)));
			exit;
		}
		$this->display();
	}
	/**
	 * 修改大美英才
	 */
	public function article_school_pic_update(){
		if ($_POST){
			$info = $this->upload_();
			if ($info){
				$savepath = $info[0]["savepath"];
				$savepath = substr($savepath, 1,strlen($savepath) - 1);//图片上传路径处理去掉.
				$_POST['pic_url'] = $savepath.$info[0]["savename"];//上传图片设置
			}
			M('Article')->save($_POST);
			$this->success('更新成功',U('ArticleSchool/article_school_pic_list',array('p'=>$_POST['p'],'c_id'=>$_POST['c_id'])));
			exit;
		}
		$p = $_GET['p'];
		$c_id = $_GET['c_id'];
		$obj = M('Article')->where("id=".$_GET['id'])->find();
		$this->assign("obj",$obj);
		$this->assign('p',$p);
		$this->assign('c_id',$c_id);
		$this->display();
	}
	/**
	 * 学校新闻列表
	 */
	public function article_school_news_list(){
		$where = '';
		if($_GET['c_id']){
			$where = "ac_id = ".$_GET['c_id'];
		}else{
			$where = "ac_id=9";
		}
		$where .= $this->my_where();
		import('ORG.Util.Page');// 导入分页类
		$count = M('Article')->where($where)->count();//总条数
		$Page = new Page($count,10);//每页显示10条
		$show = $Page->show();
		$list = M('Article')->where($where)->order('sort')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign("list",$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
	}
	/**
	 * 添加校园新闻
	 */
	public function article_school_news_add(){
		if($_POST){
			$_POST['time'] = time();
			$_POST['ac_id'] = 9;
			$_POST['visits'] = 0;//访问量初始值为0
			$_POST['content'] = stripslashes($_POST['content']);
			M('Article')->add($_POST);
			$this->success('添加成功',U('ArticleSchool/article_school_news_list',array('c_id'=>9)));
			exit;
		}
		$this->display();
	}
	/**
	 * 修改校园新闻
	 */
	public function article_school_news_update(){
		if ($_POST){
			$_POST['content'] = stripslashes($_POST['content']);
			M('Article')->save($_POST);
			$this->success('更新成功',U('ArticleSchool/article_school_news_list',array('p'=>$_POST['p'],'c_id'=>$_POST['c_id'],'search_word'=>$_POST['search_word'])));
			exit;
		}
		$search_word = $_GET['search_word'];
		$p = $_GET['p'];
		$c_id = $_GET['c_id'];
		$obj = M('Article')->where("id=".$_GET['id'])->find();
		$this->assign("obj",$obj);
		$this->assign('p',$p);
		$this->assign('c_id',$c_id);
		$this->assign('search_word',$search_word);
		$this->display();
	}
	/**
	 * 办学成绩列表
	 */
	public function article_school_ach_list(){
		$where = '';
		if($_GET['c_id']){
			$where = "ac_id = ".$_GET['c_id'];
		}else{
			$where = "ac_id=10";
		}
		$where .= $this->my_where();
		import('ORG.Util.Page');// 导入分页类
		$count = M('Article')->where($where)->count();//总条数
		$Page = new Page($count,10);//每页显示10条
		$show = $Page->show();
		$list = M('Article')->where($where)->order('sort')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign("list",$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
	}
	/**
	 * 添加办学成绩
	 */
	public function article_school_ach_add(){
		if($_POST){
			$_POST['time'] = time();
			$_POST['ac_id'] = 10;
			$info = $this->upload();
			if($info){
				$savepath = $info[0]["savepath"];
				$savepath = substr($savepath, 1,strlen($savepath) - 1);
				$_POST['pic_url'] = $savepath.$info[0]["savename"];//封面设置
			}
			M('Article')->add($_POST);
			$this->success('添加成功',U('ArticleSchool/article_school_ach_list',array('c_id'=>10)));
			exit;
		}
		$this->display();
	}
	/**
	 * 修改办学成绩
	 */
	public function article_school_ach_update(){
		if ($_POST){
			$info = $this->upload_();
			if ($info){
				$savepath = $info[0]["savepath"];
				$savepath = substr($savepath, 1,strlen($savepath) - 1);//图片上传路径处理去掉.
				$_POST['pic_url'] = $savepath.$info[0]["savename"];//上传图片设置
			}
			M('Article')->save($_POST);
			$this->success('更新成功',U('ArticleSchool/article_school_ach_list',array('p'=>$_POST['p'],'c_id'=>$_POST['c_id'])));
			exit;
		}
		$p = $_GET['p'];
		$c_id = $_GET['c_id'];
		$obj = M('Article')->where("id=".$_GET['id'])->find();
		$this->assign("obj",$obj);
		$this->assign('p',$p);
		$this->assign('c_id',$c_id);
		$this->display();
	}
	/**
	 * 编辑办学成绩简介
	 */
	public function article_school_ach_intro(){
		if($_POST){
			$_POST['content'] = stripslashes($_POST['content']);
			M('Article')->save($_POST);
			$this->success("修改成功",U('ArticleSchool/article_school_ach_list',array('c_id'=>10)));
			exit;
		}
		$obj = M('Article')->where("ac_id=15")->find();
		$this->assign('obj',$obj);
		$this->display();
	}
	/**
	 * 英才视频列表
	 */
	public function article_school_vid_list(){
		$where = '';
		if($_GET['c_id']){
			$where = "ac_id = ".$_GET['c_id'];
		}else{
			$where = "ac_id=11";
		}
		$where .= $this->my_where();
		import('ORG.Util.Page');// 导入分页类
		$count = M('Article')->where($where)->count();//总条数
		$Page = new Page($count,10);//每页显示10条
		$show = $Page->show();
		$list = M('Article')->where($where)->order('sort')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign("list",$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
	}
	/**
	 * 添加英才视频
	 */
	public function article_school_vid_add(){
		if($_POST){
			$_POST['time'] = time();
			$_POST['ac_id'] = 11;
			$info = $this->video_upload_();
			if($info){
				$savepath = $info[0]["savepath"];
				$savepath = substr($savepath, 1,strlen($savepath) - 1);
				$_POST['video_url'] = $savepath.$info[0]["savename"];//封面设置
			}
			M('Article')->add($_POST);
			$this->success('添加成功',U('ArticleSchool/article_school_vid_list',array('c_id'=>11)));
			exit;
		}
		$this->display();
	}
	/**
	 * 修改英才视频
	 */
	public function article_school_vid_update(){
		if ($_POST){
			$info = $this->video_upload_();
			if ($info){
				$savepath = $info[0]["savepath"];
				$savepath = substr($savepath, 1,strlen($savepath) - 1);//图片上传路径处理去掉.
				$_POST['video_url'] = $savepath.$info[0]["savename"];//上传图片设置
			}
			M('Article')->save($_POST);
			$this->success('更新成功',U('ArticleSchool/article_school_vid_list',array('p'=>$_POST['p'],'c_id'=>$_POST['c_id'])));
			exit;
		}
		$p = $_GET['p'];
		$c_id = $_GET['c_id'];
		$obj = M('Article')->where("id=".$_GET['id'])->find();
		$this->assign("obj",$obj);
		$this->assign('p',$p);
		$this->assign('c_id',$c_id);
		$this->display();
	}
	/**
	 * 学校简介管理方法
	 */
	public function article_school_intr_list(){
		if($_POST){
			$_POST['content'] = stripslashes($_POST['content']);
			M('Article')->save($_POST);
			$this->success("修改成功",U('ArticleSchool/article_school_intr_list',array('c_id'=>12)));
			exit;
		}
		$obj = M('Article')->where("ac_id=".$_GET['c_id'])->find();
		$this->assign('obj',$obj);
		$this->display();
	}
	/**
	 * 联系我们管理方法
	 */
	public function article_school_con_list(){
		if($_POST){
			$_POST['content'] = stripslashes($_POST['content']);
			M('Article')->save($_POST);
			$this->success("修改成功",U('ArticleSchool/article_school_con_list',array('c_id'=>13)));
			exit;
		}
		$obj = M('Article')->where("ac_id=".$_GET['c_id'])->find();
		$this->assign('obj',$obj);
		$this->display();
	}
	//删除方法
	public function article_school_delete(){
		$obj = M('Article')->where("id=".$_GET['id'])->find();
		if($obj['pic_url'] || $obj['video_url']){
			@unlink('.'.$obj['pic_url']);
			@unlink('.'.$obj['video_url']);//删除文件
		}
		M('Article')->where("id=".$_GET['id'])->delete();
		$this->success('删除成功');
	}
	//搜索配置
	public function my_where(){
		$where = '';
		$search_word = $_GET['search_word'];
		if($search_word) {
			$where .= " and (title like '%$search_word%') ";
		}
		return $where;
	}
}

?>